package ch04;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import redis.clients.jedis.Jedis;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class TestJedis {

    JedisAPI jedisAPI=null;
    @Before
    public void getConn(){
        jedisAPI = new JedisAPI();
    }

    @After
    public void destory(){
        if (null!=jedisAPI.jedisPool){
            jedisAPI.destory();
        }
    }
    @Test
    public void testJedis(){
        try {
           /* String name =jedisAPI.get("k1");
            System.out.println(name);*/
            // 中

           // System.out.println(jedisAPI.set("cly", "abc", 10000));

          //  System.out.println(jedisAPI.append("cly", "efg"));

           // jedisAPI.mset("姓名","张三","年龄","18","hobby","paly ball");

            Jedis jedis = jedisAPI.jedisPool.getResource();

/*            jedis.incr("年龄");  //值+1
            System.out.println(jedis.get("年龄"));*/

          /*  Map<String,String> maps  =new HashMap<String,String>();
            maps.put("姓名","李四");
            maps.put("年龄","18");
            maps.put("hobby","paly game");

            jedis.hmset("wcl",maps);

            List<String> lists =jedis.hmget("wcl","hobby","年龄");
            lists.forEach(s -> System.out.println(s));*/

           /* System.out.println(jedis.hlen("wcl"));
            jedis.hdel("wcl","年龄");
            System.out.println(jedis.hlen("wcl"));*/

            jedis.lpush("nums","9","8","7","6");
            System.out.println(jedis.sort("nums"));

        } catch (Exception exception) {
            exception.printStackTrace();
        } finally {

        }
    }

    public void testSet(){
        try {
           // jedisAPI.set();
        }catch (Exception e){
            e.printStackTrace();
        }finally {

        }
    }
}
